import qrcode
 
def generate_qrcode(data, filename):
    qr = qrcode.QRCode(
        version=1,
        error_correction=qrcode.constants.ERROR_CORRECT_L,
        box_size=10,
        border=4,
    )
    qr.add_data(data)
    qr.make(fit=True)
 
    img = qr.make_image(fill='black', back_color='white')
    img.save(filename)
 
# 使用函数生成二维码
generate_qrcode('weixin://pay.weixin.qq.com/bizpayurl/up?pr=NwY5Mz9&groupid=00', 'hello_world.png')
